//
//  UIViewController+MSCommon.m
//  PeopleForTheFirstMall
//
//  Created by iOS on 2020/11/16.
//  Copyright © 2020 MS. All rights reserved.
//

#import "UIViewController+MSCommon.h"

@implementation UIViewController (MSCommon)

- (UIAlertController *)showAlert:(NSString *)title
                         message:(NSString *)message
                messageAlignment:(NSTextAlignment)alignment
                      leftAction:(nullable UIAlertAction *)leftAction
                     rightAction:(nonnull UIAlertAction *)rightAction
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
                                                                   message:message
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    [alert ms_makeChains:^(MSChainMaker * _Nonnull make) {
        
        make
        .ms_titleFontAndColor([UIFont systemFontOfSize:15], MS_HEX_COLOR(0x333333))
        .ms_messageFontColorAndAlignment([UIFont systemFontOfSize:15], MS_HEX_COLOR(0x666666), alignment);
    }];
    
    [leftAction ms_makeChains:^(MSChainMaker * _Nonnull make) {
        
        make.ms_titleTextColor(MS_HEX_COLOR(0x666666))
        .ms_addToAlert(alert);
    }];
    [rightAction ms_makeChains:^(MSChainMaker * _Nonnull make) {
        
        make.ms_titleTextColor(MS_HEX_COLOR(0xff8400))
        .ms_addToAlert(alert);
    }];
    
    [self presentViewController:alert
                       animated:YES
                     completion:NULL];
    
    return alert;
}

- (UIAlertController *)showAlert:(NSString *)title
                         message:(NSString *)message
                messageAlignment:(NSTextAlignment)alignment
                          action:(UIAlertAction *)action
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
                                                                   message:message
                                                            preferredStyle:UIAlertControllerStyleAlert];
    
    [alert ms_makeChains:^(MSChainMaker * _Nonnull make) {
        
        make
        .ms_titleFontAndColor([UIFont systemFontOfSize:15], MS_HEX_COLOR(0x333333))
        .ms_messageFontColorAndAlignment([UIFont systemFontOfSize:15], MS_HEX_COLOR(0x666666), alignment);
    }];
    
    [action ms_makeChains:^(MSChainMaker * _Nonnull make) {
        
        make.ms_titleTextColor(MS_HEX_COLOR(0xff8400))
        .ms_addToAlert(alert);
    }];
    
    
    [self presentViewController:alert
                       animated:YES
                     completion:NULL];
    
    return alert;
}

@end
